import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { STColumn, STComponent } from '@delon/abc';
import { SFSchema } from '@delon/form';
import {JoaLeaveEditComponent} from "./edit/edit.component";

@Component({
  selector: 'app-joa-leave',
  templateUrl: './leave.component.html',
})
export class JoaLeaveComponent implements OnInit {
  url = `joa/leave/list`;
  searchSchema: SFSchema = {
    properties: {
      days: {
        type: 'string',
        title: '请假天数'
      },
      reason: {
        type: 'string',
        title: '请假原因'
      },
      type: {
        type: 'string',
        title: '请假类型'
      },
      bpmStatus: {
        type: 'string',
        title: '流程状态'
      },
    }
  };
  @ViewChild('st', { static: false }) st: STComponent;
  columns: STColumn[] = [
    {
      title: '请假天数',
      index: 'days'
    },
    {
      title: '请假原因',
      index: 'reason'
    },
    {
      title: '请假类型',
      index: 'type'
    },
    {
      title: '流程状态',
      index: 'bpmStatus'
    },
    {
      title: '操作',
      buttons: [
        {
          text: `删除`,
          type: 'del',
          click: (record) => this.http.delete(`joa/leave/delete?id=${record.id}`).subscribe(res => this.st.reload())
        },
        {
          text:'编辑',
          type:"modal",
          modal:{
            component:JoaLeaveEditComponent
          },
          click:"reload",
        }
      ]
    }
  ];

  constructor(private http: _HttpClient, private modal: ModalHelper) { }

  ngOnInit() { }

  add() {
    this.modal
      .createStatic(JoaLeaveEditComponent, { i: {  } })
      .subscribe(() => this.st.reload());
  }

}
